package com.mypage.adapter;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.cloudcc.mobile.R;
import com.cloudcc.mobile.manager.RunTimeManager;
import com.cloudcc.mobile.manager.UrlManager;
import com.cloudcc.mobile.util.UserUtils;
import com.lidroid.xutils.BitmapUtils;
import com.mypage.bean.SmallGroup;
import com.mypage.utils.ImageLoaderUtils_circle;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * Created by liuyongjie on 2017/6/2.
 */

public class NsmallGroupAdapter extends BaseAdapter {
    public Context context;
    public List mList;
    public String url = UrlManager.getInterfaceUrl() + "?binding=" + RunTimeManager.getInstance().getServerBinding() + "&serviceName=showChatterImage&type=user&id=";

    public NsmallGroupAdapter(Context context, List mList) {
        this.context = context;
        this.mList = mList;
    }

    @Override
    public int getCount() {
        return mList == null ? 0 : mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder mViewHolder = null;
        if (convertView == null) {
            mViewHolder = new ViewHolder();
            convertView = View.inflate(context, R.layout.small_group_item, null);
            mViewHolder.mHeader = (ImageView) convertView.findViewById(R.id.imgHeader);
            mViewHolder.mName = (TextView) convertView.findViewById(R.id.textName);
            mViewHolder.mQuanxian = (TextView) convertView.findViewById(R.id.textQdu);
            mViewHolder.mZhiwei = (TextView) convertView.findViewById(R.id.zhiweis);
            convertView.setTag(mViewHolder);
        } else {
            mViewHolder = (ViewHolder) convertView.getTag();
        }
        SmallGroup.GroupData.Sgroup obj = (SmallGroup.GroupData.Sgroup) mList.get(position);
        Log.d("request头像Url===", url + obj.userid);

        ImageLoader.getInstance().displayImage(url + obj.userid, mViewHolder.mHeader , ImageLoaderUtils_circle.MyDisplayImageOptions());


        mViewHolder.mName.setText(obj.username);
        mViewHolder.mQuanxian.setText(obj.opportunityaccesslevel);
        mViewHolder.mZhiwei.setText(obj.teammemberrole);
        return convertView;
    }

    public class ViewHolder {
        ImageView mHeader;
        TextView mName;
        TextView mQuanxian;
        TextView mZhiwei;
    }
}
